package com.itasura.strategy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 策略模式是一种策略类似锦囊妙计
 * @author sailor wang
 * @date 2018/8/27 下午12:47
 * @description
 */
public class Main {

    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        // 小轿车
        VehicleStrategy vehicleStrategy = new CarStrategy();
        //老司机
        Driver driver = new Driver(vehicleStrategy);
        //开车
        driver.drive();

        //老司机为人民服务，开公共汽车
        vehicleStrategy = new BusStrategy();
        driver.changeStrategy(vehicleStrategy);
        driver.drive();

        //老司机人生巅峰，开超跑
        vehicleStrategy = new RoadsterStrategy();
        driver.changeStrategy(vehicleStrategy);
        driver.drive();

// --------------- 老司机人生开挂，想开啥开啥 ---------------------- Java 8 Strategy pattern

        //开出租
        driver.changeStrategy(() -> LOGGER.info("体验生活，开出租。。。"));
        driver.drive();

        //开飞机
        driver.changeStrategy(() -> LOGGER.info("要上天，开飞机。。。。"));
        driver.drive();

        //开飞机
        driver.changeStrategy(() -> LOGGER.info("要下海，开游艇。。。。"));
        driver.drive();

    }
}